package com.ruoyi.project.hidden.hiddenRepair.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.hidden.hiddenRepair.domain.HiddenRepair;
import com.ruoyi.project.hidden.hiddenRepair.service.IHiddenRepairService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 隐患处理Controller
 * 
 * @author ruoyi
 * @date 2021-01-26
 */
@Controller
@RequestMapping("/hidden/hiddenRepair")
public class HiddenRepairController extends BaseController
{
    private String prefix = "hidden/hiddenRepair";

    @Autowired
    private IHiddenRepairService hiddenRepairService;

    @RequiresPermissions("hidden:hiddenRepair:view")
    @GetMapping()
    public String hiddenRepair()
    {
        return prefix + "/hiddenRepair";
    }

    /**
     * 查询隐患处理列表
     */
    @RequiresPermissions("hidden:hiddenRepair:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HiddenRepair hiddenRepair)
    {
        startPage();
        List<HiddenRepair> list = hiddenRepairService.selectHiddenRepairList(hiddenRepair);
        return getDataTable(list);
    }

    /**
     * 导出隐患处理列表
     */
    @RequiresPermissions("hidden:hiddenRepair:export")
    @Log(title = "隐患处理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HiddenRepair hiddenRepair)
    {
        List<HiddenRepair> list = hiddenRepairService.selectHiddenRepairList(hiddenRepair);
        ExcelUtil<HiddenRepair> util = new ExcelUtil<HiddenRepair>(HiddenRepair.class);
        return util.exportExcel(list, "hiddenRepair");
    }

    /**
     * 新增隐患处理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存隐患处理
     */
    @RequiresPermissions("hidden:hiddenRepair:add")
    @Log(title = "隐患处理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HiddenRepair hiddenRepair)
    {
        return toAjax(hiddenRepairService.insertHiddenRepair(hiddenRepair));
    }

    /**
     * 修改隐患处理
     */
    @GetMapping("/edit/{repairId}")
    public String edit(@PathVariable("repairId") Long repairId, ModelMap mmap)
    {
        HiddenRepair hiddenRepair = hiddenRepairService.selectHiddenRepairById(repairId);
        mmap.put("hiddenRepair", hiddenRepair);
        return prefix + "/edit";
    }

    /**
     * 修改保存隐患处理
     */
    @RequiresPermissions("hidden:hiddenRepair:edit")
    @Log(title = "隐患处理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HiddenRepair hiddenRepair)
    {
        return toAjax(hiddenRepairService.updateHiddenRepair(hiddenRepair));
    }

    /**
     * 删除隐患处理
     */
    @RequiresPermissions("hidden:hiddenRepair:remove")
    @Log(title = "隐患处理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hiddenRepairService.deleteHiddenRepairByIds(ids));
    }
}
